package com.sparrow.common.time;


import com.sparrow.common.util.CronUtil;
import com.sparrow.common.util.TimeUtil;

public enum TimeType {
    /**
     * 绝对时间
     */
    ABSOLUTE_TIME(1) {
        @Override
        public long parse(String timeString) {
            return TimeUtil.parse(timeString);
        }
    },

    /**
     * CRON表达式时间
     */
    CRON(2) {
        @Override
        public long parse(String timeString) {
            return CronUtil.parse(timeString, System.currentTimeMillis());
        }
    },
    ;
    private final int type;

    TimeType(int type) {
        this.type = type;
    }

    public abstract long parse(String timeString);

    public static void main(String[] args) {
        long time = TimeType.ABSOLUTE_TIME.parse("2023-03-16 00:00:00");
        System.out.println(time);

        long time2 = TimeType.CRON.parse("0 0 0/1 * * ? *");
        System.out.println(TimeUtil.format((int) (time2 / 1000L)));
    }
}
